<?php
require_once '../AopCertClient.php';
require_once '../AopCertification.php';
require_once '../request/AlipayTradeQueryRequest.php';
require_once '../request/AlipayTradeWapPayRequest.php';
require_once '../request/AlipayTradeAppPayRequest.php';

$aop = new AopCertClient ();
// $appCertPath = "./appCertPublicKey.crt";
// $alipayCertPath = "./alipayCertPublicKey_RSA2.crt";
// $rootCertPath = "./alipayRootCert.crt";
$appCertPath = "./appCertPublicKey_2021001142684784.crt";
$alipayCertPath = "./alipayCertPublicKey_RSA2.crt";
$rootCertPath = "./alipayRootCert.crt";

$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId ='2021001142684784';
$aop->rsaPrivateKey = 'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCBsK0+ZeN5vw7+li+pZnm8llEN/vqpc0dv1djKpQBOHc1b8QmkIv43k99fSLKodxVBa7/0LcnjwnqsKyHEhIVKcfrm5iBCJlHbK5LpNLe9l3mZCs4uFBGyc/1kPrnxsx5bC75ctzHnyA9ikTR0rC1FOn0Iqfx8Whcs3aTPJI0zrAZZKlnBBSQ9lyXT2afmfPT8m63LBf2066uQ123/nXHrvkA3xyJoamJ7yVY/1JcxtIYV21sQQ7F4C242ktjyT4TALPVsZp4hfm+h+7Buov9pys2HI0sj6IzQBLmDQmJDtRAHs5e+KHxY0s+yg5Z/KJ0kokAkbwQx1k+Lf+ZnKb/rAgMBAAECggEAWtWyIbgfYVBOYkYyz8V0kn/9+X2Td0fEyzHOi/CRjCUXhsQGaq4PvEGX/Bbg+1mcy5t6cL35X8sBPMFg/1GKQiAfCcY45dwNDSMx3KEN6H7FrkmBK4jm9ESFP8cnWYCJTF+nTy0IiTz4eaMWSHmno4tZs83LiBVZkhUTr/n75CoioZQC265qcWplUeb/PYXJLN1aHJ0CXpgELCmfzXMSxB4b5uQ4A1aWs3kXeQAUMKHO5k9kC/fzrGLs2lDRmu4+fLL1sSV+j4sZfT2UANiZm2Y/ULj+9LCFuXOdesSJVhg+27pzNNLgFyrD1P1FRr7ot/x4Jmr7MARPkiuZOzXK8QKBgQDFWM0+UCpYgqAlPSmKHengME7tqeODjOb/hlBqXaZRqITq2ctxPpfzvu9OxcpyUiVknvAo2ivMlUd8vSDNfXGeqtVAnmf2y8c/VibWd+YbgRPnaeyzqeogz/O9faRkzM8dc8a/L0wHANlZjcovCM7TmEbl2EEb8xKx2S+6KOwJNwKBgQCoPDD02VnrZeX0X4R8Y/gW+wtKz00dO6ALta21Uv/4WKKYdDwxFQnS+A8vUan3RV0NDTsomZa6//mTrterzKxpLGPoIrzbTr8Agn4CUT1Zw6k4SBxNlOxIaEigp+COyfoexVpxHjnCFZR0ZMP3N693NtHgYJL0jciD1qLIvkCI7QKBgCdXeasnfhmhCN4DoGlZZ0t7NfDpQmLyTwa3twZNXx++Uakj/Au6Z75+3OQ+SAqcV7oEeWobfEnPpK24Yna0wFbaRaMZMS6hFzqIKTvuMSBgjiA/HKIAiJ0796JaDtDNh6iecQuiGSz4PVw+CQVxYxIJtHCTuP8iaSKtYndhOxTnAoGAUIxRHEochVpKWVCKTExI8ifMZksOrtpnbHPV8aUFrVAyuS+dyho6k+n0y0EcUanCPYeCNZQj2PDJ++2QkU7zlX+Nbg2DwrTXOlVAI7fl2d6WXL4Z3wNYhep4K4N1Pqhxut3eyZ4hJU3TwE6mjOz6c+epYPacJb7krErNsbN1jpkCgYBsflDNA0mLDM1zMAtk8TZEQeL5EAUT53lEOpGVjAGvgX4r0KFLBRRGyKunWrN79ZcxOHPOIi5jab/nv6sLxC8YVPbifagCFw/RHP6ZWaxRBvM1WvZ5jWRKSNciwxPBNDJ7yTLrfYVXu6sz4g6pytZ8geAA+00UBE5letG2iS2qxA==';
$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset = 'utf-8';
$aop->format = 'json';
$aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书，如果开启校验要保证支付宝根证书在有效期内
$aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
// $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
$aop->alipayRootCertSN = '687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6';//调用getRootCertSN获取支付宝根证书序列号

$request = new AlipayTradeAppPayRequest ();
$date=date("YmdHis");
$arr=range(1000,9999);
shuffle($arr);
$request->setBizContent("{\"out_trade_no\":\"".$date.$arr[0]."\",\"total_amount\":0.01,\"product_code\":\"QUICK_MSECURITY_PAY\",\"subject\":\"app测试\"}");

$result = $aop->sdkExecute($request);
echo($result);die;
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if (!empty($resultCode) && $resultCode == 10000) {
    echo "成功";
} else {
    echo "失败";
}
echo 123;die;